package programmteile;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

/**
 * andere Menuform. mit test.gif
 */
public class Auswahlmenu extends JPanel {
	public Auswahlmenu() {
		super(new GridLayout(1, 0));

	
		Border blackline, raisedetched, loweredetched, raisedbevel, loweredbevel, empty;

	
		Border paneEdge = BorderFactory.createEmptyBorder(0, 10, 10, 10);

		blackline = BorderFactory.createLineBorder(Color.black);
		raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
		loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
		raisedbevel = BorderFactory.createRaisedBevelBorder();
		loweredbevel = BorderFactory.createLoweredBevelBorder();
		empty = BorderFactory.createEmptyBorder();


		JPanel mitglieder_btn = new JPanel();
		mitglieder_btn.setBorder(paneEdge);
		mitglieder_btn
				.setLayout(new BoxLayout(mitglieder_btn, BoxLayout.Y_AXIS));

		addCompForBorder(blackline, "Test", mitglieder_btn);
		addCompForBorder(raisedetched, "Test 2", mitglieder_btn);
		addCompForBorder(loweredetched, "Test 3", mitglieder_btn);
		addCompForBorder(raisedbevel, "Test 4", mitglieder_btn);
		addCompForBorder(loweredbevel, "Test 5", mitglieder_btn);
		addCompForBorder(empty, "Test 6", mitglieder_btn);


		JPanel abteilung = new JPanel();
		abteilung.setBorder(paneEdge);
		abteilung.setLayout(new BoxLayout(abteilung, BoxLayout.Y_AXIS));

		ImageIcon icon = createImageIcon("test.gif",
				"wavy-line border icon");
		Border border = BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
		if (icon != null) {
			addCompForBorder(border, "matte border (-1,-1,-1,-1,icon)",
					abteilung);
		} else {
			addCompForBorder(border, "matte border (-1,-1,-1,-1,<null-icon>)",
					abteilung);
		}
		border = BorderFactory.createMatteBorder(1, 5, 1, 1, Color.red);
		addCompForBorder(border, "matte border (1,5,1,1,Color.red)", abteilung);

		border = BorderFactory.createMatteBorder(0, 20, 0, 0, icon);
		if (icon != null) {
			addCompForBorder(border, "matte border (0,20,0,0,icon)", abteilung);
		} else {
			addCompForBorder(border, "matte border (0,20,0,0,<null-icon>)",
					abteilung);
		}

	
		JPanel suche = new JPanel();
		suche.setBorder(paneEdge);
		suche.setLayout(new BoxLayout(suche, BoxLayout.Y_AXIS));
		TitledBorder titled;

		titled = BorderFactory.createTitledBorder("test");
		addCompForBorder(titled, "voll der test"
				+ " (default just., default pos.)", suche);

		titled = BorderFactory.createTitledBorder(blackline, "test 2");
		addCompForTitledBorder(titled, "totaler test"
				+ " (centered, default pos.)", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, suche);

		titled = BorderFactory.createTitledBorder(loweredetched, "test 3");
		addCompForTitledBorder(titled, "uuh test"
				+ " (right just., default pos.)", TitledBorder.RIGHT,
				TitledBorder.DEFAULT_POSITION, suche);

		titled = BorderFactory.createTitledBorder(loweredbevel, "test 4");
		addCompForTitledBorder(titled, "echt test"
				+ " (default just., above top)",
				TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.ABOVE_TOP,
				suche);

		titled = BorderFactory.createTitledBorder(empty, "test 5");
		addCompForTitledBorder(titled, "boah, test.."
				+ " (default just., bottom)",
				TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.BOTTOM, suche);


		JPanel xml_Export = new JPanel();
		xml_Export.setBorder(paneEdge);
		xml_Export.setLayout(new BoxLayout(xml_Export, BoxLayout.Y_AXIS));
		Border redline = BorderFactory.createLineBorder(Color.red);

		Border compound;
		compound = BorderFactory
				.createCompoundBorder(raisedbevel, loweredbevel);
		addCompForBorder(compound, "noch son ding", xml_Export);

		compound = BorderFactory.createCompoundBorder(redline, compound);
		addCompForBorder(compound, "noch eins",
				xml_Export);

		titled = BorderFactory.createTitledBorder(compound, "test",
				TitledBorder.CENTER, TitledBorder.BELOW_BOTTOM);
		addCompForBorder(titled, "und noch eins"
				+ " (centered, below bottom)", xml_Export);

		JTabbedPane Reiter_Menu = new JTabbedPane();
		Reiter_Menu.addTab("Mitglieder", null, mitglieder_btn, null);
		Reiter_Menu.addTab("Abteilung", null, abteilung, null);
		Reiter_Menu.addTab("Suche", null, suche, null);
		Reiter_Menu.addTab("XML-Export", null, xml_Export, null);
		Reiter_Menu.setSelectedIndex(0);
		String toolTip = new String(
				"<html>Blue Wavy Line border art crew:<br>&nbsp;&nbsp;&nbsp;Bill Pauley<br>&nbsp;&nbsp;&nbsp;Cris St. Aubyn<br>&nbsp;&nbsp;&nbsp;Ben Wronsky<br>&nbsp;&nbsp;&nbsp;Nathan Walrath<br>&nbsp;&nbsp;&nbsp;Tommy Adams, special consultant</html>");
		Reiter_Menu.setToolTipTextAt(1, toolTip);

		add(Reiter_Menu);
	}

	void addCompForTitledBorder(TitledBorder border, String description,
			int justification, int position, Container container) {
		border.setTitleJustification(justification);
		border.setTitlePosition(position);
		addCompForBorder(border, description, container);
	}

	void addCompForBorder(Border border, String description, Container container) {
		JPanel comp = new JPanel(new GridLayout(1, 1), false);
		JLabel label = new JLabel(description, JLabel.CENTER);
		comp.add(label);
		comp.setBorder(border);

		container.add(Box.createRigidArea(new Dimension(0, 10)));
		container.add(comp);
	}


	protected static ImageIcon createImageIcon(String path, String description) {
		java.net.URL imgURL = Auswahlmenu.class.getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL, description);
		} else {
			System.err.println("Kanns leider nicht findeh: " + path);
			return null;
		}
	}


	private static void createAndShowGUI() {

		JFrame frame = new JFrame("Auswahlmenu");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		
		Auswahlmenu newContentPane = new Auswahlmenu();
		newContentPane.setOpaque(true); 
		frame.setContentPane(newContentPane);

		
		frame.pack();
		frame.setVisible(true);
	}

	public static void main(String[] args) {
	
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}
}